#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<unordered_map>
#include<queue>
#include<stack>
#include <functional>
#include <memory>
using namespace std;

class Solution {
public:
    int maxTurbulenceSize(vector<int>& arr) {
        int n = arr.size();
        vector<int> f(n);
        auto g = f;
        int ret1 = 0;
        for (int i = 1; i < n; i++)
        {
            if (i % 2 == 0) f[i] = (arr[i] < arr[i - 1]) ? f[i - 1] + 1 : 0;
            else f[i] = (arr[i] > arr[i - 1]) ? f[i - 1] + 1 : 0;
            ret1 = max(ret1, f[i]);
        }
        int ret2 = 0;
        for (int i = 1; i < n; i++)
        {
            if (i % 2 == 0) g[i] = (arr[i] > arr[i - 1]) ? g[i - 1] + 1 : 0;
            else g[i] = (arr[i] < arr[i - 1]) ? g[i - 1] + 1 : 0;
            ret2 = max(ret2, g[i]);
        }
        return max(ret1, ret2) + 1;
    }
};

int main()
{
    vector<int> in(30, -1);
	return 0;
}